package com.watermeter.android.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.watermeter.android.R;
import com.watermeter.android.entry.Rows;

import java.util.List;

/**待抄表路线
 * Created by zouqh on 2016/5/23.
 */
public class DcbAdapter extends BaseAdapter {
    private Context context;
    private List<Rows> rowses;

    public DcbAdapter(Context context, List<Rows> rowses) {
        this.context = context;
        this.rowses = rowses;
    }

    @Override
    public int getCount() {
        return rowses.size();
    }

    @Override
    public Object getItem(int position) {
        return rowses.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodler viewHodler;
        if (convertView == null) {
            viewHodler = new ViewHodler();
            convertView = LayoutInflater.from(context).inflate(R.layout.dai_cb_item, null);
            viewHodler.code = (TextView) convertView.findViewById(R.id.code);
            viewHodler.name = (TextView) convertView.findViewById(R.id.name);
            viewHodler.CBPerson = (TextView) convertView.findViewById(R.id.CBPerson);
            viewHodler.date = (TextView) convertView.findViewById(R.id.date);

            viewHodler.ycbn = (TextView) convertView.findViewById(R.id.ycbn);
            viewHodler.scbn = (TextView) convertView.findViewById(R.id.scbn);
            viewHodler.isSucc = (TextView) convertView.findViewById(R.id.isSucc);
            viewHodler.tState = (TextView) convertView.findViewById(R.id.tState);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHodler) convertView.getTag();
        }

        viewHodler.name.setText("线路名称：" + rowses.get(position).getNAME());
        viewHodler.code.setText("线路编号：" + rowses.get(position).getID());
        viewHodler.date.setText("抄表月份：" + rowses.get(position).getMOTH());
        viewHodler.CBPerson.setText("本月读数：" + rowses.get(position).getCBY());
        viewHodler.ycbn.setText("应抄表：" + rowses.get(position).getYCBNUM());
        viewHodler.scbn.setText("实抄表：" + rowses.get(position).getSCBNUM());
        if(rowses.get(position).getYCBNUM()==rowses.get(position).getSCBNUM()){
            viewHodler.isSucc.setText("已完成");
            viewHodler.tState.setText("已完成");
            viewHodler.isSucc.setTextColor(Color.parseColor("#FFFF7C07"));
            viewHodler.tState.setTextColor(Color.parseColor("#FFFF7C07"));
        }else {
            viewHodler.isSucc.setText("未完成");
            viewHodler.tState.setText("抄表中");
            viewHodler.isSucc.setTextColor(Color.parseColor("#FFFF4A3D"));
            viewHodler.tState.setTextColor(Color.parseColor("#FFFF4A3D"));
        }
        return convertView;
    }

    class ViewHodler {
        TextView name;
        TextView code;
        TextView CBPerson;
        TextView date;
        TextView ycbn;
        TextView scbn;
        TextView isSucc;
        TextView tState;
    }
}
